package com.tang.juc.cas.aba;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.concurrent.atomic.AtomicReference;

/**
 * @author tlm
 * @version 1.0
 * @date 2020/4/20 15:21
 * 原子引用案例
 */
public class AtomicReferenceDemo {
    public static void main(String[] args) {
        User u1 = new User("张三",15);
        User u2 = new User("李四",20);

        AtomicReference<User> atomicReference = new AtomicReference<>();
        atomicReference.set(u1);

        System.out.println(atomicReference.compareAndSet(u1, u2)+"\t"+atomicReference.get().toString());
        System.out.println(atomicReference.compareAndSet(u1, u2)+"\t"+atomicReference.get().toString());
    }


}

@Data
@AllArgsConstructor
class User{
    private String name;
    private Integer age;
}
